package entity.service;


import entity.Book;
import entity.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * BookService
 *
 * @author: cyx_jay
 * @date: 2021/1/27 14:47
 */
@Service
public class BookService {

    @Autowired
    private BookDao bookDao;

    public List<Book> findAll(){
        return bookDao.findAll();
    }



    @Transactional
    public void zhuanzhang(int id1,int id2,int price){
        Book book1 = bookDao.findById(id1);
        Book book2 = bookDao.findById(id2);
        int price1 = book1.getPrice();
        int price2 = book2.getPrice();
        bookDao.updatePriceById(1,price1-price);
        int a = 1/0;
        bookDao.updatePriceById(2,price2+price);
    }



}
